$(function () {
	 var url=window.location.host; 
	 var protocol=window.location.protocol+"//";
	  
	//merName  check  count 
    $("#merName").blur(function(){
    	if(this.value.length==0){
    		return;
    	}
    	var params=null;
    	var id=$("#mer_status").val();
    	//var  name=this.value;
    	if(id!=null && id!=""){
    		 params={"merName":this.value,"merNo":$("#isMid").val()};
    	}else{
    		 params={"merName":this.value};
    	}
    	
    	
    	$.ajax({
    		url:protocol+url+"/fmposm/merinfoAjax/getMchtNameCount.ct",
	  		data:params,
	  		dataType:"json",
	  		type:"POST",
	  		success:function(result){
		  		 var codes=result.code;
		  		 if(codes=="9999"){
		  			 $("#rtName").html(result.codeDesc);
		  		 }else{
		  			$("#rtName").html("");
		  		 }
	  		},error:function(rsg){
	  			  
	  		}
    	});
    });
	  
    //*********************************************************************************dongjie  shanghu button 
    $("#freezeMerinfoBtn").click(function(){
    	var mid=checkChooseNum();
    	if(!mid){
    		return;
    	}
    	var param={"merinfo.id":mid,"merinfo.status":"03"};
    	merinfoListAjax(param,mid);
    });  
	
  //*********************************************************************************jiedong   shanghu button 
    $("#resetFreezeMerinfoBtn").click(function(){
    	var mid=checkChooseNum();
    	if(!mid){
    		return;
    	}
    	var param={"merinfo.id":mid,"merinfo.status":"01"};
    	merinfoListAjax(param,mid);
    });  
    
  //*********************************************************************************zhuxiao  shanghu button 
    $("#logoutMerinfoBtn").click(function(){
    	var mid=checkChooseNum();
    	if(!mid){
    		return;
    	}
    	var param={"merinfo.id":mid,"merinfo.status":"02"};
    	merinfoListAjax(param,mid);
    });  
    
    //*****************************************************************************************UN area code
    $("#chooseProvice").change(function(){
    	 
		$("#chooseCity").empty();
		//$("#chooseArea").empty();
		$("#chooseCity").append("<option value=''>请选择</option>");
		//$("#chooseArea").append("<option value=''>请选择</option>");
		var is=$("#chooseProvice").val();
		var param={"proviceCode":is};
		/*'<s:url value="/address/getCityMap.ct"/>'*/
		$.ajax({
		 	url:protocol+window.location.host+"/fmposm/address/getCityMap.ct",
		 	data:param,
	  		dataType:"text",
	  		type:"POST",
	  		success:function(returnResult){ 
	  		 	var a=jQuery.parseJSON(returnResult);
	  			 for ( var b in a[0]) {
	  				
	  				$("#chooseCity").append("<option value='"+b+"'>"+ a[0][b]+ "</option>");
	  			 }   
	  		},error:function(rsg){
	  			alert("加载城市出错，请联系客服~！");
	  		}	
	 	});   		
	});
	
	$("#chooseCity").change(function(){
		//$("#chooseArea").empty();
		//$("#chooseArea").append("<option value=''>请选择</option>");
		var is=$("#chooseCity").val();
		var param={"cityCode":is};
		/*'<s:url value="/address/getAreaMap.ct"/>'*/
		$.ajax({
		 	url:protocol+window.location.host+"/fmposm/address/getAreaMap.ct",
		 	data:param,
	  		dataType:"text",
	  		type:"POST",
	  		success:function(returnResult){ 
	  		 	var a=jQuery.parseJSON(returnResult);
	  			 for ( var b in a[0]) {
	  				$("#chooseArea").append("<option value='"+b+"'>"+ a[0][b]+ "</option>");
	  			 }   
				 
	  		},error:function(rsg){
	  			alert("加载城市出错，请联系客服~！");
	  		}	
	 	});   		
	});
	 
	 
	//*******************************************************************************************mcc choose 
    $("#mccBtn").click(function(){
    	 var ScreenWidth = screen.availWidth ;
         var ScreenHeight = screen.availHeight; 
         var StartX = (ScreenWidth - innerWidth) / 2 ;
         var StartY = (ScreenHeight - innerHeight) / 2 ;
          
    	 var url = protocol+window.location.host+"/fmposm/chooseBank/initMcc.ct";
    	
    	 window.open(url, '选择MCC', 'left='+ StartX + ', top='+ StartY + ', Width=' + innerWidth +', height=' + innerHeight + ', resizable=no, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no'); 
    });
});

function checkChooseNum(){
	var dd = $("input[name=multi_sel]:checked");
	var accountNo = dd.val();
	if(dd.length == 0){
		$("#msgInfo").html("请选择商户");
		return false;
	}else if(dd.length != 1){
		$("#msgInfo").html("只能选择一个商户进行操作");
		return false;
	}else{
		if(accountNo==null || accountNo==""){
			$("#msgInfo").html("获取商户失败");
			return false;
		}
		$("#msgInfo").html("");
		$("input[name='merinfoListBtn']").each(function(){
			$("#"+this.id).attr("disabled",true);
		});
		return accountNo;
	}
}

function  merinfoListAjax(param,mid){
	 
	var url=window.location.host; 
	 
	$.ajax({
		url:protocol+url+"/fmposm/formalMerinfo/changeMerinfoStatus.ct",
  		data:param,
  		dataType:"json",
  		type:"POST",
  		success:function(result){
  			$("input[name='merinfoListBtn']").each(function(){
  				$("#"+this.id).removeAttr("disabled");
  			});
  			var resultInfo=result.jsonBean;
  			if(resultInfo.code=="0000"){
  				$("#s_"+mid).html(resultInfo.codeDesc);
  			}
  			$("#msgInfo").html(resultInfo.codeDesc);
  			 
  		},error:function(rsg){
  			$("input[name='merinfoListBtn']").each(function(){
  				$("#"+this.id).removeAttr("disabled");
  			});
  		}
	});
}

function queryOneOrgName(){
	var oneOrgName = $("#inputOneOrgName").val(); 
	if(oneOrgName != null && oneOrgName.trim() != "" ) {
		// 机构号设为初始状态
		$("#oneagentid").val("");
		$("#oneagentid option").each(function(){
			if($(this).text() == oneOrgName){  
				var oneOrgCode = $(this).val();
				$("#oneagentid").val(oneOrgCode);
			}
		});
	}
}
